﻿using System;
using System.Text.RegularExpressions;
using ReAnimation.DAL.Domain.Policies.Interfaces;
using ReAnimation.DAL.Domain.Policies.Interfaces.ErrorEnums;
using NameValidationResultType =
    ReAnimation.Helpers.Common.ValidationResult
        <ReAnimation.DAL.Domain.Policies.Interfaces.ErrorEnums.IncorrectMoleculeNameErrors>;

namespace ReAnimation.DAL.Domain.Policies
{
    public class MoleculePolicy : IMoleculePolicy
    {
        #region IMoleculePolicy Members

        public NameValidationResultType CheckName(string name)
        {
            if (String.IsNullOrEmpty(name))
                return
                    NameValidationResultType.FailValidation(IncorrectMoleculeNameErrors.EmptyString);

            var regex = new Regex("^[a-zA-Z]*$");
            if (!regex.IsMatch(name))
                return
                    NameValidationResultType.FailValidation(IncorrectMoleculeNameErrors.NonLatinCharacters);

            return NameValidationResultType.SuccessValidation();
        }

        #endregion
    }
}